
template<class K,class R, class Lik, class Prop, class Filter>
class SmcSampler
{
	public:
	SmcSampler(mat X, double *Y, int M, mat m, mat S)
	{
		_X=X;
		_Y=Y;
		_M=M;
		_p=X.n_cols;
		_m=m;
		_S=S;
	}
	void operator()(void)
	{
		int numCPU = sysconf(_SC_NPROCESSORS_ONLN);
		//numCPU=1;
		cout << "cpu  " << numCPU;
		mat A((int)(_M/numCPU),_p);
		mat w((int)(_M/numCPU),1);
		vector<mat> weights(numCPU,w);
		vector<mat> Pi(numCPU,A);
		vector<mat> Phi;
		vector<mat> Acc;
		mat Z(numCPU,1);	
		int i=0;
		#pragma omp parallel for firstprivate(R,K,G,F,DP,P), shared(Pi,weights,Z, Phi,Acc)
			for(int i=0;i<numCPU;i++)
			{	
				G=new Prop(_p,_m,_S);
				//G=new Distribution::Student(p[0],200,m,s);
				F=new Prop(_p,_m,_S);
				//DP=new Probit_st::Probit3(Y,X,F,S,7);
				DP=new Lik(_Y,_X,F,_S);
				k=new K<Filter,Prop>(DP,G);
				r=new R;
				P=new Particle<K<Filter,Prop>,R,Filter>(k,r,DP,(int)(_M/numCPU),F);
				P->Filter();
				Pi[i]=P->Get_theta();
				weights[i]=P->Get_W();
				Z(i,0)=P->Get_Z();	
				Phi.push_back(P->Get_Phiv());
				Acc.push_back(P->Get_Acc());
			}
	}
	
	private:
		mat _X;
		double *_Y;
		int _p;
		int _M;
		mat _m;
		mat _S;
		R *r;
		Prop *G; 
		Prop *F; 
		Lik *DP;
		K<Filter,Prop> *k;
		Particle<K<Filter,Prop>,R,F>  *P;
	
};

